package com.lu.service;

import com.lu.mapper.UserMapper;
import com.lu.pojo.User;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.*;

@Component
public class UserService {
    public static String uimg;
    @Resource
    private UserMapper userMapper;
    public List<User> getUser(String uaccount,String upwd){
        Map<String, Object> map = new HashMap<>();
        map.put("uaccount",uaccount);
        map.put("upwd",upwd);
        return userMapper.selectByMap(map);
    }
    public List<User> setUser(String uname, String upwd, String uage){
        User user = new User();
        Map<String, Object> map = new HashMap<>();
        List<User> users1 = new ArrayList<>();
        while (true){
            int rs = (int) ((Math.random() * 9 + 1) * Math.pow(10, 9 - 1));
            System.out.println(rs);
            uimg = String.valueOf(rs);
            map.put("uaccount",String.valueOf(rs));
            if(Objects.equals(userMapper.selectByMap(map),users1)){
                user.setUname(uname);
                user.setUpwd(upwd);
                user.setUage(uage);
                user.setUaccount(String.valueOf(rs));
                user.setUimg("http://8.130.95.37:8084/icon/"+ rs +".jpg");
                userMapper.insert(user);
                return userMapper.selectByMap(map);
            }
        }
    }
    public List<User> getUser2(int uid){
        Map<String, Object> map = new HashMap<>();
        map.put("uid",uid);
        return userMapper.selectByMap(map);
    }
    public List<User> getUserAdd(String uaccount){
        Map<String, Object> map = new HashMap<>();
        map.put("uaccount",uaccount);
        return userMapper.selectByMap(map);
    }
}
